#ifndef __REG__HEADER__
#define __REG__HEADER__

#include "paramconfig.h"
#include "common.h"
#include "osipparser2/osip_message.h"

class SipReg
{
public:
    enum State
    {
        REG_STATUS_NOLOGIN,
        REG_STATUS_LOGINING,
        REG_STATUS_LOGINAUTH,
        REG_STATUS_LOGIN,
        REG_STATUS_LOGINFAILED,
        REG_STATUS_LOGOUTING,
        REG_STATUS_LOGOUT
    };

    SipReg(eXosip_t* ctx, const ConfigParam& param);

    bool sendRegister(int rid = 0, int expires = 0);
    bool sendRefreshRegister();
    bool sendUnRegister();
    void transitionState(State target);
    int getRegid() const { return mRegId; }
    bool success() const { return (REG_STATUS_LOGIN == mRegState); }
    bool inReg() const { return !(REG_STATUS_NOLOGIN == mRegState || REG_STATUS_LOGOUT == mRegState); }

protected:
    osip_message_t* makeRegister(int rid = 0, int expires = 0);
    void removeRegister();
    static std::string toString(State s);

    const ConfigParam&  mParam;
    eXosip_t*           mSipCtx;
    State               mRegState;
    int                 mRegId;
    osip_contact_t*     mContact;
};

#endif //#ifndef __REG__HEADER__
